home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 8154 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.4 KB  |  82 lines

  1. Newsgroups: comp.lang.c++
  2. Path: newsfeed.internetmci.com!btnet!bt!btcase!Pearl
  3. From: muthu@mbtpost.agw.bt.co.uk (Muthu Kumar)
  4. Subject: Re: const usage as #define
  5. Message-ID: <4fujng$7o_001@agw.bt.co.uk>
  6. Sender: news@btcase.bt.co.uk (USENET News System)
  7. Organization: MBT
  8. X-Newsreader: News Xpress Version 1.0 Beta #4
  9. References: <4frc93$2s8@fmsu03.fm.intel.com>
  10. Date: Thu, 15 Feb 1996 06:26:56 GMT
  11.  
  12. In article <4frc93$2s8@fmsu03.fm.intel.com>,
  13.    tomtzigt@frx215.intel.com (Theodore Omtzigt - MPG MAP - FOLSOM) wrote:
  14. >Path: 
  15. btcase!bt!btnet!tank.news.pipex.net!pipex!news.mathworks.com!newsfeed.internet
  16. mci.com!in1.uu.net!inews.intel.com!itnews.sc.intel.com!fmsu03.fm.intel.com!frx
  17. 215!tomtzigt
  18. >From: tomtzigt@frx215.intel.com (Theodore Omtzigt - MPG MAP - FOLSOM)
  19. >Newsgroups: comp.lang.c++
  20. >Subject: const usage as #define
  21. >Date: 14 Feb 1996 01:01:23 GMT
  22. >Organization: Intel Corporation
  23. >Lines: 33
  24. >Distribution: ca
  25. >Message-ID: <4frc93$2s8@fmsu03.fm.intel.com>
  26. >NNTP-Posting-Host: frx215.fm.intel.com
  27. >Status: N
  28. >
  29. >We are trying to port a piece of C++ code to different platforms.
  30. >The code was developed with GNU g++, but we would like to use
  31. >the native compilers that come with the different platforms.
  32. >On IBM we use c++, on HP we use cfront, and on NT we use VC++.
  33. >Now the following situation arises: given this piece of code
  34. >
  35. >class foo {
  36. >    private:
  37. >        const int SIZE = 10;
  38. >        int array[SIZE];
  39. >    public:
  40. >        foo();
  41. >};
  42. >
  43. >The intend has probably been to use the 'const int SIZE' like a 
  44. >#define macro to parameterize the static allocation of 'array'.
  45. >GNU g++ has no problem with this intend, and IBM c++ also accepts
  46. >this const initializer, but Cfront and VC++ do like the const
  47. >initialization. If you then try to use the foo bla : SIZE(10)
  48. >style to initialize the const int SIZE then you run in the 
  49. >problem of not being able to compile int array[SIZE] appropriately.
  50. >
  51. >What is the proper C++ way of doing the above?
  52. >
  53. >Since I don't read this news group regularly, please respond directly 
  54. >through email. Thanks in advance,
  55. >
  56. >Theo
  57.  
  58.  
  59. Use enum.
  60.  
  61. class foo {
  62. private:
  63.     enum { SIZE=10};
  64.     int array[SIZE];
  65. public:
  66.     foo();
  67. };
  68.  
  69. Hope this helps.
  70.     
  71.  
  72. =~=~=~=~=~=~=~=~=~=~==~=~=~=~=~=~=~=~=
  73. K. Muthu Kumar
  74. 14 Shreeji Apartments,
  75. Kondi Vitta Village,
  76. Bombay - 59.
  77. INDIA.
  78. Ph: (O) +91-22-836 78 42
  79.     (R) +91-22-839 08 21
  80. Internet: muthu@mbtpost.agw.bt.co.uk
  81. =~=~=~=~=~=~=~=~=~=~==~=~=~=~=~=~=~=~=
  82.